package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.PolicyDocuments;
import com.ruoyi.system.service.IPolicyDocumentsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 文件Controller
 *
 * @author ruoyi
 * @date 2023-12-01
 */
@RestController
@RequestMapping("/system/documents")
public class PolicyDocumentsController extends BaseController {
    @Autowired
    private IPolicyDocumentsService policyDocumentsService;

    /**
     * 查询文件列表
     */
    @PreAuthorize("@ss.hasPermi('system:documents:list')")
    @GetMapping("/list")
    public TableDataInfo list(PolicyDocuments policyDocuments) {
        startPage();
        List<PolicyDocuments> list = policyDocumentsService.selectPolicyDocumentsList(policyDocuments);
        return getDataTable(list);
    }

    /**
     * 导出文件列表
     */
    @PreAuthorize("@ss.hasPermi('system:documents:export')")
    @Log(title = "文件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PolicyDocuments policyDocuments) {
        List<PolicyDocuments> list = policyDocumentsService.selectPolicyDocumentsList(policyDocuments);
        ExcelUtil<PolicyDocuments> util = new ExcelUtil<PolicyDocuments>(PolicyDocuments.class);
        util.exportExcel(response, list, "文件数据");
    }

    /**
     * 获取文件详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:documents:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(policyDocumentsService.selectPolicyDocumentsById(id));
    }

    /**
     * 新增文件
     */
    @PreAuthorize("@ss.hasPermi('system:documents:add')")
    @Log(title = "文件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PolicyDocuments policyDocuments) {
        return toAjax(policyDocumentsService.insertPolicyDocuments(policyDocuments));
    }

    /**
     * 修改文件
     */
    @PreAuthorize("@ss.hasPermi('system:documents:edit')")
    @Log(title = "文件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PolicyDocuments policyDocuments) {
        return toAjax(policyDocumentsService.updatePolicyDocuments(policyDocuments));
    }

    /**
     * 删除文件
     */
    @PreAuthorize("@ss.hasPermi('system:documents:remove')")
    @Log(title = "文件", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(policyDocumentsService.deletePolicyDocumentsByIds(ids));
    }

    /**
     * 获取数据
     */
    @Log(title = "获取数据", businessType = BusinessType.OTHER)
    @GetMapping("/queryPolicy")
    public AjaxResult queryPolicy() {
        policyDocumentsService.queryPolicy();
        return AjaxResult.success();
    }
}
